<template>
  <div id="app">
    <div id="nav">
      <el-row>
        <el-col :span="4">
          <div id="logo">
            <img src="../assets/logo-02.png" alt="" />
          </div>
        </el-col>
        <el-col :span="9" class="bot" :offset="5">
          <router-link to="/main/home">主页</router-link>
          <router-link to="/main/warehouse">疾病库</router-link>
          <router-link to="/main/experience">疾病经验</router-link>
          <router-link to="/main/knowledge">疾病知识</router-link>
          <router-link to="/main/video">疾病视频</router-link></el-col
        >
        <el-col :span="3" class="inf">
          <el-autocomplete
            class="inline-input"
            v-model="state2"
            :fetch-suggestions="querySearch"
            placeholder="请输入疾病名称"
            @select="handleSelect"
          >
            <i class="el-icon-search" slot="suffix" @click="chaxun"> </i>
          </el-autocomplete>
        </el-col>
        <el-col :span="3" class="inf" style="width: 160px; cursor: pointer">
          <span class="iconll">
            <span class="userName" @click="login">{{ userName }}</span
            >&nbsp;
            <el-avatar
              shape="circle"
              size="medium"
              :src="squareUrl"
              @click.native="login"
            >
            </el-avatar>
            <div class="liebiao">
              <p class="line" @click="clickRouter(1)">
                <i class="el-icon-user"></i>我的主页
              </p>
              <p class="line" @click="clickRouter(2)">
                <i class="iconfont icon-gongzuojingyan"></i>我的经验
              </p>
              <p class="line" @click="clickRouter(3)">
                <i class="iconfont icon-31liebiao"></i>账户设置
              </p>
              <p @click="clickRouter(4)">
                <i class="el-icon-turn-off"></i>退出
              </p>
            </div>
            <!-- <el-dropdown @command="clickRouter">
              <span class="el-dropdown-link">
                <el-avatar shape="circle" size="medium" :src="squareUrl"
                @click.native="login">
                </el-avatar>
              </span>
              <el-dropdown-menu slot="dropdown" class="drop1">
                <el-dropdown-item command="1"
                  ><i class="el-icon-user"></i>我的主页</el-dropdown-item
                >
                <el-dropdown-item
                  ><i class="iconfont icon-gongzuojingyan"></i
                  >我的经验</el-dropdown-item
                >
                <el-dropdown-item
                  ><i class="el-icon-turn-off"></i>退出</el-dropdown-item
                >
              </el-dropdown-menu>
            </el-dropdown> -->
          </span>
          
        </el-col>
      </el-row>
    </div>
    <div>
      <!--keep-alive 表示页面不会被销毁，即保持页面状态-->
      <keep-alive>
        <router-view v-if="$route.meta.keepalive"></router-view>
      </keep-alive>
      <router-view ref="con1" v-if="!$route.meta.keepalive"></router-view>
    </div>
    <footer class="ft mi-bg">
      <el-row type="flex" justify="center">
        <el-col :span="7" class="rline">
          <ul class="lul">
            <li>
              <router-link to="/main/home">回到首页</router-link>
            </li>
            <li>
              <routerLink to="/main/warehouse">疾病库</routerLink>
            </li>

            <li>
              <routerLink to="/main/knowledge">疾病知识</routerLink>
            </li>
            <li>
              <routerLink to="/main/experience">疾病经验</routerLink>
            </li>
            <li>
              <routerLink to="/main/video">疾病视频</routerLink>
            </li>
            <li>
              <routerLink to="/main/MyHome">我的主页</routerLink>
            </li>
            <li>
              <routerLink to="/main/myexp/relexpr">我的经验</routerLink>
            </li>
          </ul>
        </el-col>
        <el-col :span="7" class="focen rline">
          <div class="img"><img src="../assets/logo03.png" alt="" /></div>
          <div class=""></div>
          <h5>TEL</h5>
          <h4>234-5678</h4>
        </el-col>
        <el-col :span="7" class="fori">
          <el-autocomplete
            class="inline-input"
            v-model="state2"
            :fetch-suggestions="querySearch"
            placeholder="请输入疾病名称"
            @select="handleSelect"
          >
            <i class="el-icon-search" style="lineHeight:40px" slot="suffix" @click="chaxun"> </i>
          </el-autocomplete>
          <p>Email:2827932693@qq.com</p>
        </el-col>
      </el-row>
      <el-row type="flex" justify="center">
        <a href="https://beian.miit.gov.cn/" target="_blank">蜀ICP备2022018248号-1</a>
      </el-row>
    </footer>
  </div>
</template>
<script>
export default {
  inject: ["reload"],
  data() {
    return {
      sicknessNames: [], //疾病列表
      state2: "", //搜索内容
      state3: "", //搜索内容
      userName: this.$getStorage("userinfo")
        ? this.$getStorage("userinfo").nickname
        : "登录",
      squareUrl: this.$getStorage("userinfo")
        ? this.$getStorage("userinfo").headImg
        : "https://cube.elemecdn.com/9/c2/f0ee8a3c7c9638a54940382568c9dpng.png", //头像
    };
  },
 
  methods: {
    querySearch(queryString, cb) {
      var restaurants = this.sicknessNames;
      var results = queryString
        ? restaurants.filter(this.createFilter(queryString))
        : restaurants;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    createFilter(queryString) {
      return (restaurant) => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
          0
        );
      };
    },
    handleSelect() {
      this.chaxun()
    },
    chaxun() {
      if(this.$route.name!="Warehouse"){
        //点击查询
      this.$router.push({ name: "Warehouse", params: { input: this.state2 } });
      }else{
        this.$refs.con1.input2=this.state2;
        this.$refs.con1.search()
      }
      
    },
    clickRouter(command) {
      if (command === 1) {
        this.$router.push({ path: "/main/MyHome/myall" });
      } else if (command === 2) {
        this.$router.push({ path: "/main/myexp/relexpr" });
      } else if (command === 3) {
        this.$router.push({ path: "/main/accset/myinfo" });
      } else if (command === 4) {
        //判断是否登录
        let isLogin = this.$getStorage("isLogin");
        if (!isLogin) {
          this.$message({
            message: "暂未登录",
            type: "warning",
          });
        } else {
          this.$axios({
            method: "post",
            url: "/user/loginOut",
          }).then((res) => {
            console.log(res);
            if (res.code == "200") {
              this.$message({
                message: "退出成功",
                type: "success",
              });
              
              this.$setStorage("isLogin", false);
              this.$removeStorage("userinfo");
              this.$removeStorage("token");
              this.reload();
              this.$store.commit("changeLog",false);
            }
          });
        }
      }
    },
    login() {
      //未登录则跳到登录页面
      if (!this.$getStorage("isLogin")) {
        this.$router.push("/main/login");
      } else {
        this.$router.push({ path: "/main/MyHome/myall" });
      }
    },
  },
  created() {
   this.$axios({
      method: "get",
      url: "/sickness/searchName",
    })
      .then((res) => {
        this.sicknessNames = res.data;
      })
      .catch((err) => {
        console.log(err);
      });
  },
};
</script>

<style lang="less" scoped>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;
  padding-top: 70px;
}
.exp {
  width: 100%;
  background-color: #f2f7fb;
  & > div {
    width: 1200px;
    margin: 0 auto;
  }
}
.el-input {
  .el-input__inner {
    border-radius: 38px;
    background-color: #312a6d;
    color: #dcdfe6;
    border: none;
  }
}

#nav {
  position: fixed;
  top: 0;
  z-index: 4;
  width: calc(100% - 2px);
  background-color: #9ba5bb;
  height: 70px;
  border-bottom: 2px solid #312a6d;
  line-height: 70px !important;
  padding: 0 10px;
  ::v-deep .el-input__inner {
    border-radius: 38px;
    background-color: #312a6d;
    color: #dcdfe6;
    border: none;
  }
  .userName {
    display: inline-block;
    width: 80px;
    text-align: right;
    white-space: nowrap;
    /* 文字溢出部分已经省略号的形式进行显示 */
    text-overflow: ellipsis;
    /* 文字溢出部分影藏 */
    overflow: hidden;
  }
  #logo {
    overflow: hidden;
    height: 70px;
    img {
      margin-top: -60px;
      width: 200px;
    }
  }
  .bot {
    a {
      display: inline-block;
      height: 70px;
      box-sizing: border-box;
      margin: 0 20px;
      line-height: 70px;
      color: #312a6d;
      font-size: 18px;
    }
    .router-link-exact-active {
      border-bottom: 4px solid #312a6d;
    }
  }
  .inf {
    line-height: 70px;
    span {
      vertical-align: middle;
    }
    & > .iconll {
      position: relative;
      &:hover > .liebiao {
        height: 200px;
        padding: 10px 0;
      }
      i {
        font-size: 30px;
        margin-left: 15px;
        color: #312a6d;
      }
      .liebiao {
        position: absolute;
        overflow: hidden;
        top: 45px;
        right: -20px;
        z-index: 9991;
        width: 140px;
        height: 0px;
        padding: 0 0;
        background-color: #312a6d;
        color: rgb(201, 201, 201);
        border-radius: 5px;
        transition: all 0.3s;
        box-shadow: 0 0 10px 10px #aaaaaa20;
        i {
          font-size: 20px;
          color: rgb(189, 189, 189);
          margin-right: 5px;
        }
        p {
          height: 50px;
          line-height: 50px;
          margin: 0 10px;
          text-align: left;
          user-select: none;
          &:hover,
          &:hover > i {
            color: white;
          }
        }
        .line {
          border-bottom: 1px solid rgb(104, 103, 165);
        }
      }
    }
  }
}
.el-popper .popper__arrow {
  display: none;
}
// .drop1 {
//   top: 50px !important;
// }
.el-dropdown-menu__item:not(.is-disabled):hover {
  color: #312a6d;
}
a {
  color: #9ba5bb;
  text-decoration: none;
}
* {
  margin: 0;
  padding: 0;
}
.ft {
  padding: 60px;
}
.lul {
  margin-right: 60px;
  & > li {
    color: #9ba5bb;
    height: 50px;
    line-height: 50px;
    text-align: right;
    & > a:hover {
      color: #fff;
    }
  }
}
.inline-input{
  i{
    margin-right: 10px;
    display: inline-block;
  }
}
.rline {
  border-right: 1px solid #9ba5bb;
}
.focen {
  position: relative;
  .img {
    & > img {
      width: 230px;
    }

    &::after {
      content: "";
      height: 40px;
      width: 2px;
      position: absolute;
      top: 220px;
      left: 260px;
      background-color: rgba(255, 255, 255, 0.3);
    }
  }
  h5 {
    margin-top: 35px;
    color: rgba(255, 255, 255, 0.3);
    font-size: 15px;
  }
  h4 {
    color: rgba(255, 255, 255, 0.3);
    letter-spacing: 3px;
    font-size: 25px;
    font-weight: 400;
    margin-top: 5px;
  }
}
.fori {
  text-align: left;
  padding-left: 70px;
  padding-top: 80px;
  p {
    margin-top: 50px;
    color: rgba(255, 255, 255, 0.3);
    letter-spacing: 1px;
  }
}
</style>